#############################################
# 1 项目配置
#############################################

cmake_minimum_required( VERSION 3.0.0 )
project( STL_Mqtt VERSION 0.1.0 )


#############################################
# 2 路径配置
#############################################

# make时的可执行文件输出路径
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output)

# 设置安装根目录
SET(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)



# SET(DESTINATION ${PROJECT_SOURCE_DIR}/install)
message(STATUS "=======================================")
message(STATUS "路径设置")
message(STATUS "---------------------------------------")
message(STATUS "PROJECT_NAME:${PROJECT_NAME}")
message(STATUS "PROJECT_BINARY_DIR:${PROJECT_BINARY_DIR}")
message(STATUS "PROJECT_SOURCE_DIR:${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_INSTALL_PREFIX:${CMAKE_INSTALL_PREFIX}")
# message(STATUS "DESTINATION:${DESTINATION}")
message(STATUS "---------------------------------------")


#############################################
# 3 编译选项
#############################################
set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -g")
# set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-stack-check")

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-check")


add_definitions(
    -DLYL_DEBUG
)

#############################################
# 4 头文件搜索路径
#############################################

include_directories(
    .
    ..
    ../../STL_Json
    ../../STL_Utils
    ../../STL_Log
    ../../STL_Timestamp
    ../../../libs/jsoncpp
)

message(STATUS "=======================================")
message(STATUS "头文件搜索路径")
message(STATUS "---------------------------------------")
get_property(temp_directories DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message(STATUS "INCLUDE_DIRECTORIES: ${temp_directories}")
message(STATUS "---------------------------------------")

#############################################
# 5 库文件搜索路径
#############################################

# # openssl库路径
# link_directories(
#     "./libs/openssl/lib"
# )

# # zlog库路径
# link_directories(
#     "/opt/data/log/zlog-1.2.14/src"
# )

# # jsoncpp库路径
# link_directories(
#     "/opt/data/sip/jsoncpp/build/debug/src/lib_json"
# )

message(STATUS "=======================================")
message(STATUS "库搜索路径")
message(STATUS "---------------------------------------")
foreach(src_filename ${LINK_DIRECTORIES})
    message(STATUS ${src_filename})
endforeach(src_filename)
message(STATUS "---------------------------------------")


#############################################
# 6 源码路径
#############################################

aux_source_directory(. SRC_LIST)
aux_source_directory(.. SRC_LIST)
aux_source_directory(../../STL_Json SRC_LIST)
aux_source_directory(../../STL_Log SRC_LIST)
aux_source_directory(../../STL_Timestamp SRC_LIST)
aux_source_directory(../../../libs/jsoncpp SRC_LIST)

message(STATUS "=======================================")
message(STATUS "项目源文件列表")
message(STATUS "---------------------------------------")
foreach(src_filename ${SRC_LIST})
    message(STATUS ${src_filename})
endforeach(src_filename)
message(STATUS "---------------------------------------")

#############################################
# 7 目标生成
#############################################
message(STATUS "=======================================")
message(STATUS "目标文件")
message(STATUS "---------------------------------------")
message(STATUS ${PROJECT_NAME})
message(STATUS "---------------------------------------")
add_executable( ${PROJECT_NAME} ${SRC_LIST} )

#############################################
# 8 连接动态库静态库
#############################################

# pthread
target_link_libraries(
    ${PROJECT_NAME}
    -lpthread
)

# mysqlclient
target_link_libraries(
    ${PROJECT_NAME}
    -lmysqlclient
)

#############################################
# 9 安装配置
#############################################

# make install时的可执行文件输出路径（相对于CMAKE_INSTALL_PREFIX的目录）
# install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(TARGETS ${PROJECT_NAME} DESTINATION .) 

#############################################
# 结束
#############################################
